//
//  DHS2_Brand_HeadCell.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/7/7.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHS2_Brand_HeadCell.h"

@interface DHS2_Brand_HeadCell()

@property (weak, nonatomic) IBOutlet UIImageView *logoImgView;
@property (weak, nonatomic) IBOutlet UIButton *likeButton;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *lineViewLeftLayout;

@property (strong, nonatomic) NSDictionary *brandInfo;

@property (assign, nonatomic) BOOL isLiked;

@end

@implementation DHS2_Brand_HeadCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [self.likeButton bk_addEventHandler:^(id sender) {
        if (self.isLiked) {
            [self.likeButton setImage:[UIImage imageNamed:@"product_unlike"] forState:UIControlStateNormal];
            [[DHNetAPIClient shareDHNetAPIClient] request_brand_collectWithParams:@{@"brand_id":self.brandID,@"collect":[NSNumber numberWithBool:!self.isLiked]} andBlock:^(id data, NSError *error) {
                self.isLiked = !self.isLiked;
            }];
        }else{
            [self.likeButton setImage:[UIImage imageNamed:@"product_like"] forState:UIControlStateNormal];
            [[DHNetAPIClient shareDHNetAPIClient] request_brand_collectWithParams:@{@"brand_id":self.brandID,@"collect":[NSNumber numberWithBool:!self.isLiked]} andBlock:^(id data, NSError *error) {
                self.isLiked = !self.isLiked;
            }];
        }
    } forControlEvents:UIControlEventTouchUpInside];
}

- (void)updateCell:(NSDictionary *)dic{
    self.brandInfo = dic;
    
    [self.logoImgView dh_setImageURLString:[self.brandInfo objectForKey:@"cover"]];
    
    self.isLiked = [[self.brandInfo objectForKey:@"collected"] boolValue];
    
    if (self.isLiked) {
        [self.likeButton setImage:[UIImage imageNamed:@"product_like"] forState:UIControlStateNormal];
    }else{
        [self.likeButton setImage:[UIImage imageNamed:@"product_unlike"] forState:UIControlStateNormal];
    }
}

- (IBAction)spAction:(id)sender {
    [self routerEventWithName:@"sp_action" userInfo:nil];
    self.lineViewLeftLayout.constant = 10;
}

- (IBAction)xxAction:(id)sender {
    [self routerEventWithName:@"xx_action" userInfo:nil];
    self.lineViewLeftLayout.constant = 77;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
